<template>
	<view class="main">
		<!-- ======================================【顶部栏】====================================== -->
		<MyHead :title="title"></MyHead>
		<!-- ===================================================================================== -->
	
		<view class="container">
			<swiper class="swiperContainer" :indicator-dots="false" @change="switchCard" :current="questionId-1">
				<swiper-item v-for="(question, index) in questionList" :key="question.id">
					
					<view class="topic">
						<view class="head">
							<text class="title">绪论T【名师题库】</text>
							<text>{{question.id - 1}}/{{(questionList.length)}}</text>
						</view>
						
						<view class="progressLine">
							<u-line-progress :percent="progress" :round="true" active-color="rgb(68, 162, 141)" height="15" :showPercent="false"></u-line-progress>
						</view>
						
						<view class="question">算法的计算量的大小称为算法的（  ）。</view>
						
						<view class="information">
							<text>单选</text>
							<text style="width: 120rpx;">准确率：？</text>
							<text>答题卡</text>
						</view>
					</view>
			
			
					<view class="answers-container">
						<view :class="{answers: true, answers_active: item.isClicked}"
							  v-for="(item, index) in answers" 
							  :key="index"
							  @click="clickAnswer(item)"
						>
							<text>{{item.opt}}</text>
							<text>{{item.content}}</text>
						</view>
					</view>
					
				</swiper-item>
			</swiper>
			
			
			<view class="changeQuestionButton">
				<view class="last" @click="LastQuestion">上一题</view>
				<view class="next" @click="NextQuestion">下一题</view>
			</view>
			
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			title: '正在答题',
			questionId: 1,
			progress: 0,
			questionList: [
				{ id: 1 },{ id: 2 },{ id: 3 },{ id: 4 },{ id: 5 },{ id: 6 },{ id: 7 },{ id: 8 },{ id: 9 },{ id: 10 }
			],
			answers: [
				{
					opt: 'A',
					content: '效率',
					isClicked: false,
					activeColor: '#29b3c7'
				},
				{
					opt: 'B',
					content: '复杂度',
					isClicked: false,
					activeColor: '#29b3c7'
				},
				{
					opt: 'C',
					content: '现实性',
					isClicked: false,
					activeColor: '#29b3c7'
				},
				{
					opt: 'D',
					content: '难度',
					isClicked: false,
					activeColor: '#29b3c7'
				}
			]
		};
	},
	onLoad(params){
		console.log(params)
	},
	methods: {
		clickAnswer(item){
			// item.isClicked = !item.isClicked
			this.answers.forEach((i) =>{
				if(i.opt == item.opt){
					i.isClicked = !i.isClicked
				}else{
					i.isClicked = false
				}
			})
			console.log(item)
		},
		switchCard(e){
			let currentIndex = e.detail.current;
			// 由于 questionList 的 id 从1开始，而数组索引从0开始，所以需要加1
			this.questionId = currentIndex + 1
			this.progress = (this.questionId - 1) * 10
			console.log(this.questionId)
			console.log(this.progress)
			e.preventDefault(); // 阻止默认行为
			e.stopPropagation(); // 阻止事件冒泡
		},
		LastQuestion(){
			if (this.questionId > 1) {
				this.questionId = this.questionId - 1
			} else {
				uni.showToast({
					title: '这是第一题',
					icon: 'error',
					duration: 2000 // 显示时长
				});
			}
		},
		NextQuestion(){
			if (this.questionId < this.questionList.length) {
				this.questionId = this.questionId + 1
			} else {
				uni.showToast({
					title: '这是最后一题',
					icon: 'error',
					duration: 2000 // 显示时长
				});
			}
		}
	}
};
</script>


<style>
	page {
		background-image: url('https://gd-hbimg.huaban.com/68bb9dee1eed7f34673120d61b18a29d88adcb83713c9-hDYMPo_fw480webp'); 
		background-size: 100% 100%;
	}
</style> 
<style lang="less" scoped>
.main {
	width: 100%;
	height: 100%;
	
	.container {
		color: #fff;
		width: 100%;
		height: 90vh; /* 设置具体高度 */
		min-height: 90vh;
		border-top-left-radius: 45px;
		border-top-right-radius: 45px;
		padding: 20px;
		padding-left: 55rpx;
		padding-right: 55rpx;
		position: relative;
		overflow: hidden;
		background-color: rgb(47, 52, 76);

		.swiperContainer {
			width: 100%;
			height: 100%;
			border-radius: 15px;
	
			swiper-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				width: 100%;
				height: 100%;
				flex-shrink: 0; /* 防止内容被裁剪 */
		
				.topic {
					// background-color: rgba(255, 255, 255, 0.1);
					border-radius: 15px;
					padding: 20px;
					width: 100%;
					margin-bottom: 20px;
			
					.head {
						display: flex;
						justify-content: space-between;
						align-items: center;
				
						.title {
							font-size: 24px;
							font-weight: bold;
						}
					}

					.progressLine {
						margin: 20px 0;
					}
			
					.question {
						font-size: 18px;
						margin-top: 20px;
					}
			
					.information {
						display: flex;
						align-items: center;
						margin-top: 15px;
				
						text {
							width: 90rpx;
							border-radius: 7px;
							line-height: 43rpx;
							height: 46rpx;
							text-align: center;
							font-size: 12px;
							background-image: linear-gradient(to bottom, rgb(28, 32, 45), rgb(63, 68, 93));
							margin-right: 15px;
						}
					}
				}

				.answers-container {
					width: 100%;
					display: flex;
					flex-direction: column;
					align-items: center;
			
					.answers {
						background-color: rgb(47, 52, 76);
						border-radius: 10px;
						padding: 15px;
						margin-bottom: 40rpx;
						cursor: pointer;
						border: 1px solid #fff;
						width: 90%;
						height: 135rpx;
						display: flex;
						align-items: flex-start;

						text {
							display: block;
							margin-top: 13px;
							margin-right: 20rpx;
						}
					}
					.answers_active {
						background-color: #29b3c7;
					}
				}
			}
		}
	}
	
	.changeQuestionButton{
	    position: absolute;
	    bottom: 80rpx;
	    left: 10rpx;
	    width: 100%;
	    height: 105rpx;
	    display: flex;
	    justify-content: space-around;
		
		.last,.next{
		    width: 40%;
		    height: 100%;
		    text-align: center;
		    font-size: 23px;
		    line-height: 110rpx;
		    border-radius: 50rpx;
		    background-color: #3b425a;
		}
	}
}
</style>